package com.cy.dda.web.front.goodsdiligencing;

import com.cy.dda.comm.utils.CommonUtils;
import com.cy.dda.model.Result;
import com.cy.dda.model.ao.goodsdiligencing.MaintainReportSaveAO;
import com.cy.dda.model.vo.goodsdiligencing.MaintainReportDetailVO;
import com.cy.dda.service.goodsdiligencing.MaintainReportService;
import com.cy.dda.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Description 前台-家具尽调 维护报告 controller
 * @Author tanyilin
 * @Date 2019/8/29 14:10
 */
@RestController
@RequestMapping("/user/goods/diligencing/maintain/report")
@Api(tags = "前台-家具尽调  maintain维护报告 controller")
public class MaintainReportController extends BaseController {

    @Autowired
    private MaintainReportService maintainReportService;

    @ApiOperation("维护报告详情回显")
    @GetMapping("/get/detail")
    public Result<MaintainReportDetailVO> getDetail(@RequestParam(value = "goodsDiligencingId") Long goodsDiligencingId) {

        MaintainReportDetailVO detailVO = maintainReportService.getMaintainReportDetail(goodsDiligencingId);
        return ok("获取维护报告数据成功".concat(CommonUtils.isEmpty(detailVO) ? "，但无数据" : ""), detailVO);
    }

    @ApiOperation("提交保存维护报告")
    @PostMapping("/do/save")
    public Result<Map<String, Object>> doSave(@RequestBody @Validated MaintainReportSaveAO saveAO, BindingResult bindingResult) {

        this.checkError(bindingResult);

        Result<Map<String, Object>> result = maintainReportService.saveMaintainReport(saveAO, this.getUser().getUserId());

        return result;
    }

}
